package springapp.web;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import springapp.entity.CompanyEntity;
import springapp.service.CompanyService;
import springapp.service.IDesignationService;
import springapp.service.ILocationService;
import springapp.util.Utils;

@Controller
public class CompanyController implements IControllerConstants {

	@Autowired(required = true)
	private CompanyService companyService;

	@Autowired(required = true)
	private IDesignationService designationService;

	@Autowired(required = true)
	private ILocationService locationService;

	@RequestMapping(value = "/CompanyD.htm", method = RequestMethod.GET)
	public ModelAndView handleRequest(
			@RequestParam("companyId") String companyId) throws Exception {

		CompanyEntity entity = this.companyService.getCompany(Utils.getInt(companyId));
		// companyService.populateCompany(company);
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		Set<String> allDesignations = designationService.getAllDesignations();
		jsonMap.put("designations", allDesignations);
		Set<String> allLocations = locationService.getAllLocations();
		jsonMap.put("locations", allLocations);
		jsonMap.put("company", entity);
		return new ModelAndView("Company.jsp", "jsonMap", jsonMap);
	}

}
